//
//  BaseTableViewController.swift
//  Swift-SinaWeibo
//
//  Created by 陈高健 on 15/12/12.
//  Copyright © 2015年 陈高健. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,
VisitorLoginViewDelegate {

    var userLogin = UserAccountViewModel().userLogin
    var visitorLoginView: VisitorLoginView?
    
   override func loadView() {
        if userLogin {
            super.loadView()
        }else{
            setVisitorLoginView()
        }
    }
    
    
    private func setVisitorLoginView() {
        
        visitorLoginView = VisitorLoginView()
        visitorLoginView?.visitorViewDelegate = self
        view = visitorLoginView
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "userWillLogin")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    
    func userWillLogin() {
        print(__FUNCTION__)
        let oauth = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        print(__FUNCTION__)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}
